package com.net.shop.car.manager.ui.personalcenter.dingdan;

import com.google.zxing.WriterException;
import com.net.shop.car.manager.BaseActivity;
import com.net.shop.car.manager.R;
import com.net.shop.car.manager.api.model.DingdanDetail;
import com.net.shop.car.manager.utils.Constants.DingDanType;
import com.net.shop.car.manager.utils.encoding.EncodingHandler;

import android.content.res.Resources.NotFoundException;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class BinaryCodeView {
	
	private ImageView imageView;
	private TextView goodName;
	private TextView dingdanNum;
	private TextView serviceType;
	private TextView pingjiaBtn;
	private TextView shenqingtuikuanBtn;
	private BaseActivity activity;
	
	public BinaryCodeView(View view,BaseActivity activity) {
		imageView = (ImageView) view.findViewById(R.id.binarycode_bitmap_iv);
		goodName = (TextView) view.findViewById(R.id.binarycode_bitmap_goodname);
		dingdanNum = (TextView)view.findViewById(R.id.binarycode_bitmap_dingdan);
		serviceType = (TextView) view.findViewById(R.id.binarycode_bitmap_servicetype);
		pingjiaBtn = (TextView) view.findViewById(R.id.binarycode_bitmap_btn);
		shenqingtuikuanBtn = (TextView)view.findViewById(R.id.binary_code_tuikuan);
		this.activity = activity;
	}
	
	/**
	 * @param detail DingdanDetail
	 */
	public void setData(final DingdanDetail detail,final DingDanType danType) {
		goodName.setText("确认【" + detail.getGoodName()+"】订单");
		dingdanNum.setText(detail.getOrderId());
		try {
			Bitmap bitmap = EncodingHandler.createQRCode(detail.getOrderId(), 
					activity.getResources().getDimensionPixelSize(R.dimen.binary_bitmap_width));
			imageView.setImageBitmap(bitmap);
		} catch (NotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (WriterException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if (danType == DingDanType.vbmail) {
			serviceType.setText("积分兑换");
		} else if (danType == DingDanType.outline) {
			serviceType.setText("当面付");
		} else if (danType == DingDanType.online) {
			serviceType.setText("线上支付");
			shenqingtuikuanBtn.setVisibility(View.VISIBLE);
			shenqingtuikuanBtn.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
					tukuanShenqing(detail);
				}
			});
		}
		pingjiaBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				pingJia(detail,danType);
			}
		});
	}

	protected void pingJia(DingdanDetail detail, DingDanType danType) {
		
	}

	protected void tukuanShenqing(DingdanDetail detail) {
		
	}

}
